package com.toogu.mazhangmen.service;

import android.app.Activity;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;

public class DestoryService extends Service {

    private static List<Activity> activityList=new ArrayList<>();

    public static void add(Activity activity){
        activityList.add(activity);
    }

    public static void remove(Activity activity){
        activityList.remove(activity);
        if(activityList.size()==0) activity.stopService(new Intent(activity, DestoryService.class));
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        Log.d("Destory", "onDestroy: "+activityList);
        super.onDestroy();
        for(Activity activity: activityList){
            activity.finish();
        }
        stopService(new Intent(this,SockService.class));
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}
